//
// Forms
// --------------------------------------------------


// Normalize non-controls
//
// Restyle and baseline non-control form elements.

legend {
  margin-bottom: @line-height-computed;
  font-size: (@font-size-base * 1.5);
}


// Normalize form controls
//
// While most of our form styles require extra classes, some basic normalization
// is required to ensure optimum display with or without those classes to better
// address browser inconsistencies.

// Position radios and checkboxes better
input[type="radio"],
input[type="checkbox"] {
  margin: 2px 0 0;
}

// Adjust output element
output {
  padding-top: (@padding-base-vertical + 1);
  font-size: @font-size-base;
  line-height: @line-height-base;
  color: @input-color;
}


// Common form controls
//
// Shared size and type resets for form controls. Apply `.form-control` to any
// of the following form controls:
//
// select
// textarea
// input[type="text"]
// input[type="password"]
// input[type="datetime"]
// input[type="datetime-local"]
// input[type="date"]
// input[type="month"]
// input[type="time"]
// input[type="week"]
// input[type="number"]
// input[type="email"]
// input[type="url"]
// input[type="search"]
// input[type="tel"]
// input[type="color"]

.form-control {
  /*height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)*/
  padding: @padding-base-vertical @padding-base-horizontal;
  font-size: @font-size-base;
  line-height: @line-height-base;
  background-color: @input-bg;
  border: 1px solid @input-border;
  border-top-color: darken(@input-border, 10%);
  border-radius: @input-border-radius;
  .box-shadow(none);
  .transition(none);
  /*-webkit-appearance: none; // remove iOS input shadow*/

  &:hover {
    border: 1px solid #b9b9b9;
    border-top-color: #a0a0a0;
    .box-shadow(inset 0 1px 2px rgba(0,0,0,0.1));
  }

  // Customize the `:focus` state to imitate native WebKit styles.
  .form-control-focus();

  // Disabled and read-only inputs
  //
  // HTML5 says that controls under a fieldset > legend:first-child won't be
  // disabled if the fieldset is disabled. Due to implementation difficulty, we
  // don't honor that edge case; we style them as disabled anyway.
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: @input-bg-disabled;
    border: 1px solid #e5e5e5;
    &:hover,
    &:focus,
    &:active {
      border: 1px solid #e5e5e5;
      .box-shadow(none);
    }
  }
  &[readonly] & {
    border: 1px solid @input-border;
    &:hover,
    &:focus,
    &:active {
      border: 1px solid @input-border;
    }
  }

  textarea& {
    padding-right: 4px;
  }
}

// Special styles for iOS temporal inputs
//
// In Mobile Safari, setting `display: block` on temporal inputs causes the
// text within the input to become vertically misaligned.
// As a workaround, we set a pixel line-height that matches the
// given height of the input. Since this fucks up everything else, we have to
// appropriately reset it for Internet Explorer and the size variations.

input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  line-height: @input-height-base;
  // IE8+ misaligns the text within date inputs, so we reset
  line-height: @line-height-base ~"\0";

  &.input-sm {
    line-height: @input-height-small;
  }
  &.input-lg {
    line-height: @input-height-large;
  }
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.

.radio,
.checkbox {
  min-height: @line-height-computed; // clear the floating input if there is no label text
}
input[type="radio"],
.radio input[type="radio"],
.radio-inline input[type="radio"],
input[type="checkbox"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  position: relative;
  width: 13px;
  height: 13px;
  background: white;
  border: 1px solid #dcdcdc;
  border-radius: 1px;
  -webkit-appearance: none;

  // override styles for IE
  border-width: 0 \0;

  &:focus {
    outline: 0;
    border-color: @brand-primary;
  }

  &:active {
    border-color: #c6c6c6;
    background-color: #ebebeb;
    // override the bkgd color for IE
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffffffff', GradientType=0);
  }

  &:checked {
    background: #fff;
  }
}
input[type="radio"],
.radio input[type="radio"],
.radio-inline input[type="radio"] {
  border-radius: 1em;
  width: 15px;
  height: 15px;

  &:checked::after {
    content: '';
    display: block;
    position: relative;
    top: 3px;
    left: 3px;
    width: 7px;
    height: 7px;
    background: #666;
    border-radius: 1em;
  }
}
input[type="checkbox"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  &:hover {
    border-color: #c6c6c6;
    .box-shadow(inset 0 1px 1px rgba(0, 0, 0, 0.1));

    // no box shadow for IE
    box-shadow: none e("\9");
  }

  &:checked::after {
    content: url(../images/element/checkmark.png);
    display: block;
    position: absolute;
    top: -6px;
    left: -5px;
  }
}


// Form control sizing
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.

.input-sm {
  .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @border-radius-small);
}

.input-lg {
  .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @border-radius-large);
}


// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.

.has-feedback {
  // Ensure icons don't overlap text
  .form-control {
    padding-right: (@input-height-base * 1.25);
  }
}

// Feedback icon (requires .glyphicon classes)
.form-control-feedback {
  top: (@line-height-computed + 5); // Height of the `label` and its margin
  width: @input-height-base;
  height: @input-height-base;
  line-height: @input-height-base;
}
.input-lg + .form-control-feedback {
  width: @input-height-large;
  height: @input-height-large;
  line-height: @input-height-large;
}
.input-sm + .form-control-feedback {
  width: @input-height-small;
  height: @input-height-small;
  line-height: @input-height-small;
}

// Feedback states
.has-success {
  .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
}
.has-warning {
  .form-control-validation(darken(@alert-warning-border, 20%); darken(@alert-warning-border, 20%); @state-warning-bg);
}
.has-error {
  .form-control-validation(#dd4b39; #dd4b39; @state-danger-bg);
}


// Static form control text
//
// Apply class to a `p` element to make any string of text align with labels in
// a horizontal form layout.


// Help text
//
// Apply to any element you wish to create light text for placement immediately
// below a form control. Use for general help, formatting, or instructional text.

.help-block {
  color: lighten(@text-color, 26.5%); // lighten the text some for contrast
}


// Horizontal forms
//
// Horizontal forms are built on grid classes and allow you to create forms with
// labels on the left and inputs on the right.

.form-horizontal .control-label,
.form-horizontal .radio-inline,
.form-horizontal .checkbox-inline {
  padding-top: @padding-base-vertical;
}



// Inline forms
//
// Make forms appear inline(-block) by adding the `.form-inline` class. Inline
// forms begin stacked on extra small (mobile) devices and then go inline when
// viewports reach <768px.
//
// Requires wrapping inputs and labels with `.form-group` for proper display of
// default HTML form controls and our custom form controls (e.g., input groups).
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.

.form-inline {

  // Kick in the inline
  @media (min-width: @screen-sm-min) {
    // Inline-block all the things for "inline"
    .form-group {
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }

    // In navbar-form, allow folks to *not* use `.form-group`
    .form-control {
      display: inline-block;
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
      vertical-align: middle;
    }

    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
    }

    // Remove default margin on radios/checkboxes that were used for stacking, and
    // then undo the floating of radios and checkboxes to match (which also avoids
    // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
      vertical-align: middle;

      label {
        padding-left: 0;
      }
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
      float: none;
      margin-left: 0;
      margin-bottom: -2px;
    }

    // Validation states
    //
    // Reposition the icon because it's now within a grid column and columns have
    // `position: relative;` on them. Also accounts for the grid gutter padding.
    .has-feedback .form-control-feedback {
      top: 0;
    }
  }
}


// Horizontal forms
//
// Horizontal forms are built on grid classes and allow you to create forms with
// labels on the left and inputs on the right.

.form-horizontal {

  // Consistent vertical alignment of radios and checkboxes
  //
  // Labels also get some reset styles, but that is scoped to a media query below.
  .radio,
  .checkbox,
  .radio-inline,
  .checkbox-inline {
    padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  }
  // Account for padding we're adding to ensure the alignment and of help text
  // and other content below items
  .radio,
  .checkbox {
    min-height: (@line-height-computed + (@padding-base-vertical + 1));
  }

  .form-control-static {
    padding-top: (@padding-base-vertical + 1);
    padding-bottom: (@padding-base-vertical + 1);
  }

  // Reset spacing and right align labels, but scope to media queries so that
  // labels on narrow viewports stack the same as a default form example.
  @media (min-width: @screen-sm-min) {
    .control-label {
      padding-top: (@padding-base-vertical + 1); // Default padding plus a border
    }
  }
}
